#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

struct people
{
	int head;
	char name[1000];
}people[100000];

int main()
{
	int n, m, loc = 0, step;
	int dir;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%d %s", &people[i].head,people[i].name);
	}
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &dir, &step);
		if (dir == people[loc].head)loc = (loc - step + n) % n;
		else if (dir != people[loc].head)loc = (loc + step) % n;
		printf("\t%d\n", loc);
	}
	printf("%s", people[loc].name);
	return 0;
}